﻿using AutoMapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TR.AppService.Dto;
using TR.AppService.Dto.XSddDto;
using TR.Domain.Entity;
using TR.Domain.Entity.XSDDGL;
using TR.Domain.Repository.XSDD_GuanLiRepository;

namespace TR.AppService.AppService.XSDD_GuanLi
{
    public class XsddAppService : IXsddAppService
    {
        private readonly IMapper mapper;
        private readonly IXsddRepository ixs;

        public XsddAppService(IMapper mapper, IXsddRepository ixs)
        {
            this.mapper = mapper;
            this.ixs = ixs;
        }

        //销售订单分页查询
        public async Task<DtoFenYe<XSdd>> XsddFenYeAsync(int mys, int dqy, string? qsj, string? hsj, tjXsddDto xsddDto)
        {
            XSdd xsdd =  mapper.Map<XSdd>(qsj);
            var listFenYe = await ixs.XsddFenYeSelect(mys, dqy, qsj, hsj, xsdd);
            var zts = await ixs.XsCount();
            var res = new DtoFenYe<XSdd>()
            {
                dqy = dqy,
                mys = mys,
                list = listFenYe,
                zts = zts
            };
            return res;
        }

        //批量删除
        public async Task<bool> XsddDelete(List<int> isdel)
        {
            return await ixs.XsddDelete(isdel);
        }

        //批量审核
        public async Task<bool> XsddShenHe(List<int> Bian, string states, string sureman, string suredate)
        {
            return await ixs.XsddShenHe(Bian, states, sureman, suredate);
        }

        //批量撤销
        public async Task<bool> XsddCheXiao(List<int> Bian)
        {
            return await ixs.XsddCheXiao(Bian);
        }

        //客户信息查询
        public async Task<List<bs_Customer>> KHSelect()
        {
            return await ixs.KHSelect();
        }

        //客户编号查询相关信息
        public async Task<bs_Customer> KHBHSelect(string bh)
        {
            return await ixs.KHBHSelect(bh);
        }

        //销售新增
        public async Task<bool> XsddInsert(XsddJcxx jcxx, List<XsddXsmx> xsmx)
        {
            XsddJcxx xsjc = mapper.Map<XsddJcxx>(jcxx);
            var xsxq = mapper.Map<List<XsddXsmx>>(xsmx);
            return await ixs.XsddInsert(xsjc, xsxq);
        }

        //销售修改
        public async Task<bool> XsddUpdate(XsddJcxx jcxx, List<XsddXsmx> xsmx)
        {
            XsddJcxx xsjc = mapper.Map<XsddJcxx>(jcxx);
            var xsxq = mapper.Map<List<XsddXsmx>>(xsmx);
            return await ixs.XsddUpdate(xsjc, xsxq);
        }

        //销售基本信息查询
        public async Task<wh_Sale_h> XsddJbxxSelect(string tj)
        {
            return await ixs.XsddJbxxSelect(tj);
        }

        //销售详情
        public async Task<List<XsddXsxqCX>> XsddXsxqSelect(string tj)
        {
            return await ixs.XsddXsxqSelect(tj);
        }

        //添加查询销售商品信息
        public async Task<List<XsddTjSP>> XsddTjSPSelect()
        {
            return await ixs.XsddTjSPSelect();
        }
    }
}
